home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / lib / cryptsetup / cryptdisks.functions < prev   
Encoding:
Text File  |  2011-03-11  |  15.0 KB  |  677 lines

  1. #
  2. # This file is for inclusion with
  3. #    . /lib/cryptsetup/cryptdisks.functions
  4. # and should not be executed directly.
  5.  
  6. PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  7. TABFILE="/etc/crypttab"
  8. CRYPTDISKS_ENABLE="Yes"
  9.  
  10. #set -x
  11.  
  12. # Sanity checks
  13. [ -x /sbin/cryptsetup ] || exit 0
  14. [ -f "$TABFILE"       ] || exit 0
  15.  
  16. . /lib/lsb/init-functions
  17.  
  18. if [ -r /etc/default/cryptdisks ]; then
  19.     . /etc/default/cryptdisks
  20. fi
  21.  
  22. MOUNT="$CRYPTDISKS_MOUNT"
  23.  
  24. # Parses the option field from the crypttab file
  25. parse_opts () {
  26.     local opts opt IFS PARAM VALUE
  27.  
  28.     # Strip comments - https://bugs.launchpad.net/bugs/185380
  29.     opts=$(echo -n $1 | sed 's/ *#.*//')
  30.     PARAMS=""
  31.     CHECK=""
  32.     CHECKARGS=""
  33.     PRECHECK=""
  34.     TRIES="3"
  35.     TMPFS=""
  36.     MAKESWAP=""
  37.     USELUKS=""
  38.     KEYSCRIPT=""
  39.     IGNORE=""
  40.     CRYPTTAB_OPTIONS=""
  41.     LOUD="$DEFAULT_LOUD"
  42.  
  43.     # Parse the options field, convert to cryptsetup parameters
  44.     # and construct the command line
  45.     IFS=','
  46.     for opt in $opts; do
  47.         PARAM=$(echo "$opt" | sed 's/=.*//')
  48.         VALUE=$(echo "$opt" | sed '/=/!d;s/^.*=//')
  49.         
  50.         case "$PARAM" in 
  51.         readonly)
  52.             PARAMS="$PARAMS -r"
  53.             ;;
  54.         cipher)
  55.             if [ -z "$VALUE" ]; then
  56.                 log_warning_msg "$dst: no value for cipher option, skipping"
  57.                 return 1
  58.             fi
  59.             PARAMS="$PARAMS -c $VALUE"
  60.             ;;
  61.         size)
  62.             if [ -z "$VALUE" ] || echo "$VALUE" | grep -q "^[[:digit:]]\+$" && [ "$VALUE" -gt 0 ]; then
  63.                 PARAMS="$PARAMS -s $VALUE"
  64.             else
  65.                 log_warning_msg "$dst: option size used with an incorrect argument, skipping"
  66.                 return 1
  67.             fi
  68.             ;;
  69.         hash)
  70.             if [ -z "$VALUE" ]; then
  71.                 log_warning_msg "$dst: no value for hash option, skipping"
  72.                 return 1
  73.             fi
  74.             PARAMS="$PARAMS -h $VALUE"
  75.             ;;
  76.         offset)
  77.             if [ -z "$VALUE" ]; then
  78.                 log_warning_msg "$dst: no value for offset option, skipping"
  79.                 return 1
  80.             fi
  81.             PARAMS="$PARAMS -o $VALUE"
  82.             ;;
  83.         skip)
  84.             if [ -z "$VALUE" ]; then
  85.                 log_warning_msg "$dst: no value for skip option, skipping"
  86.                 return 1
  87.             fi
  88.             PARAMS="$PARAMS -p $VALUE"
  89.             ;;
  90.         verify)
  91.             PARAMS="$PARAMS -y"
  92.             ;;
  93.         check)
  94.             if [ -z "$VALUE" ]; then
  95.                 VALUE="$CRYPTDISKS_CHECK"
  96.             fi
  97.             if [ -x "$VALUE" ]; then
  98.                 CHECK="$VALUE"
  99.             elif [ -x "/lib/cryptsetup/checks/$VALUE" ]; then
  100.                 CHECK="/lib/cryptsetup/checks/$VALUE"
  101.             else
  102.                 log_warning_msg "check $VALUE is not an executable script, skipping"
  103.                 return 1
  104.             fi
  105.             ;;
  106.         checkargs)
  107.             if [ -n "$VALUE" ]; then
  108.                 CHECKARGS="$VALUE"
  109.             fi
  110.             ;;
  111.         precheck)
  112.             if [ -z "$VALUE" ]; then
  113.                 VALUE="$CRYPTDISKS_PRECHECK"
  114.             fi
  115.             if [ -x "$VALUE" ]; then
  116.                 PRECHECK="$VALUE"
  117.             elif [ -x "/lib/cryptsetup/checks/$VALUE" ]; then
  118.                 PRECHECK="/lib/cryptsetup/checks/$VALUE"
  119.             else
  120.                 log_warning_msg "precheck $VALUE is not an executable script, skipping"
  121.                 return 1
  122.             fi
  123.             ;;
  124.         tries)
  125.             if echo "$VALUE" | grep -q "^[[:digit:]]\+$" && [ "$VALUE" -gt 0 ]; then
  126.                 TRIES="$VALUE"
  127.             else
  128.                 log_warning_msg "$dst: option tries used with an incorrect argument - forced to $TRIES"
  129.             fi
  130.             ;;
  131.         swap)
  132.             MAKESWAP="yes"
  133.             SWCHECK="/lib/cryptsetup/checks/un_blkid"
  134.             SWCHECKARGS="swap"
  135.             ;;
  136.         tmp)
  137.             if [ -z "$VALUE" ]; then
  138.                 TMPFS="ext2"
  139.             else
  140.                 TMPFS="$VALUE"
  141.             fi
  142.             ;;
  143.         luks)
  144.             USELUKS="yes"
  145.             ;;
  146.         noearly)
  147.             if [ "$INITSTATE" = "early" ]; then
  148.                 IGNORE="yes"
  149.             fi
  150.             ;;
  151.         noauto)
  152.             if [ "$INITSTATE" != "manual" ]; then
  153.                 IGNORE="yes"
  154.             fi
  155.             ;;
  156.         loud)
  157.             LOUD="yes"
  158.             ;;
  159.         quiet)
  160.             LOUD=""
  161.             ;;
  162.         keyscript)
  163.             if [ -n "$KEYSCRIPT" ]; then
  164.                 log_warning_msg "$dst: multiple key decryption options are not allowed together, skipping"
  165.                 return 1
  166.             elif [ -x "$VALUE" ]; then
  167.                 KEYSCRIPT="$VALUE"
  168.             elif [ -x "/lib/cryptsetup/scripts/$VALUE" ]; then
  169.                 KEYSCRIPT="/lib/cryptsetup/scripts/$VALUE"
  170.             elif [ -z "$VALUE" ]; then
  171.                 log_warning_msg "$dst: no value for keyscript option, skipping"
  172.                 return 1
  173.             else
  174.                 log_warning_msg "script $VALUE is not an executable script, skipping"
  175.                 return 1
  176.             fi
  177.             ;;
  178.         esac
  179.  
  180.         CRYPTTAB_OPTIONS="$CRYPTTAB_OPTIONS $PARAM"
  181.         [ -z "$VALUE" ] && VALUE="yes"
  182.         eval export CRYPTTAB_OPTION_$PARAM="\"$VALUE\""
  183.     done
  184.     export CRYPTTAB_OPTIONS
  185.  
  186.     return 0
  187. }
  188.  
  189. # Set up loopback devices
  190. lo_setup () {
  191.     #local loopdev
  192.  
  193.     if [ ! -f "$src" ]; then
  194.         return 0
  195.     fi
  196.  
  197.     if [ ! -x /sbin/losetup ]; then
  198.         return 1
  199.     fi
  200.  
  201.     if ! grep -q "[[:space:]]loop$" /proc/devices; then
  202.         modprobe -qb loop > /dev/null 2>&1 || return 1
  203.     fi
  204.  
  205.     loopdev=$(losetup -f 2> /dev/null) || return 1
  206.  
  207.     losetup "$loopdev" "$src" || return 1
  208.     src="$loopdev"
  209.     return 0
  210. }
  211.  
  212. rm_lo_setup () {
  213.     if [ "x${src%/dev/loop[0-9]}" = "x" ]; then
  214.         src="$(losetup $src | sed -e 's/^.*(\(.*\))$/\1/g' || true)"
  215.     fi
  216.  
  217.     if [ ! -f "$src" ]; then
  218.         return 0
  219.     fi
  220.  
  221.     if [ -n "$loopdev" ]; then
  222.         losetup -d "$loopdev" || return 1
  223.     fi
  224.     return 0
  225. }
  226.  
  227. # Sanity check for keys
  228. check_key () {
  229.     local GMODE OMODE OWNER GROUP
  230.  
  231.     # If the keyscript option is set, the "key" is just an argument to
  232.     # the keyscript and not necessarily a file
  233.     if [ -n "$KEYSCRIPT" ]; then
  234.         return 0
  235.     fi
  236.  
  237.     if [ -z "$key" ] || [ "$key" = "none" ]; then
  238.         key=""
  239.         return 0
  240.     fi
  241.  
  242.     if [ ! -e "$key" ]; then
  243.         log_warning_msg "$dst: keyfile not found"
  244.         return 1
  245.     fi
  246.  
  247.     # stat is unfortunately in /usr/bin...
  248.     OMODE=$(ls -l "$key" | sed 's/[[:space:]].*//;s/^.\{7\}//')
  249.     GMODE=$(ls -l "$key" | sed 's/[[:space:]].*//;s/^.\{4\}\(.\{3\}\).*/\1/')
  250.     GROUP=$(ls -l "$key" | sed 's/^.\{11\}[^[:space:]]* [^[:space:]]* \([^[:space:]]*\).*/\1/')
  251.     # regex needs to work if keyfile has xattrs - https://launchpad.net/bugs/231339
  252.     OWNER=$(ls -l "$key" | sed 's/^.\{10\}[+]\?.[^[:space:]]* \([^[:space:]]*\).*/\1/')
  253.  
  254.     # LUKS requires a persistent key, /dev/*random is not supported
  255.     if [ "$USELUKS" = "yes" ] && [ "$key" != "${key%random}" ]; then
  256.         log_warning_msg "$dst: LUKS does not work with random data as key"
  257.         return 1
  258.     fi
  259.  
  260.     # Check owner
  261.     if [ "$OWNER" != "root" ]; then
  262.         log_warning_msg "$dst: INSECURE OWNER FOR $key, see /usr/share/doc/cryptsetup/README.Debian."
  263.     fi
  264.  
  265.     # If key is random, we're done
  266.     if [ "$key" != "${key%random}" ]; then
  267.         return 0
  268.     fi
  269.  
  270.     # Check group and other permissions
  271.     if [ "$OMODE" != "---" ] || [ "$GROUP" != "root" ] && [ "$GMODE" != "---" ]; then
  272.         log_warning_msg "$dst: INSECURE MODE FOR $key, see /usr/share/doc/cryptsetup/README.Debian."
  273.     fi
  274.  
  275.     return 0
  276. }
  277.  
  278. # Setup a luks mapping
  279. do_luks () {
  280.     local tried keyscriptarg
  281.     tried=0
  282.     keyscriptarg=""
  283.  
  284.     if ! cryptsetup isLuks "$src" >/dev/null 2>&1; then
  285.         log_warning_msg "$dst: device '$src' is not a LUKS partition, skipping"
  286.         return 1
  287.     fi
  288.  
  289.     if [ -n "$KEYSCRIPT" ]; then
  290.         # keyscript => "key" is just an argument to the keyscript
  291.         keyscriptarg="$key"
  292.         key="-"
  293.     elif [ -z "$key" ]; then
  294.         # no keyscript, no key => password
  295.         keyscriptarg="Unlocking the disk $src ($dst)\nEnter passphrase: "
  296.         key="-"
  297.         if [ -x /bin/plymouth ] && plymouth --ping; then
  298.             KEYSCRIPT="plymouth ask-for-password --prompt"
  299.             keyscriptarg=$(printf "$keyscriptarg")
  300.         else
  301.             KEYSCRIPT="/lib/cryptsetup/askpass"
  302.         fi
  303.     elif [ "$key" != "${key%/dev/*}" ]; then
  304.         # no keyscript, device key => special treatment
  305.         keyscriptarg=""
  306.         key="$key"
  307.         KEYSCRIPT=""
  308.     else
  309.         # no keyscript, key => file input
  310.         keyscriptarg="$key"
  311.         key="-"
  312.         KEYSCRIPT="cat"
  313.     fi
  314.  
  315.     PARAMS="$PARAMS --key-file=$key"
  316.  
  317.     while [ "$tried" -lt "$TRIES" ]; do
  318.         if [ -n "$KEYSCRIPT" ]; then
  319.             if $KEYSCRIPT "$keyscriptarg" | cryptsetup $PARAMS luksOpen "$src" "${dst}_unformatted"; then
  320.                 break
  321.             fi
  322.         else
  323.             if cryptsetup $PARAMS luksOpen "$src" "${dst}_unformatted"; then
  324.                 break
  325.             fi
  326.         fi
  327.  
  328.         tried=$(( $tried + 1 ))
  329.         if [ "$tried" -ge "$TRIES" ]; then
  330.             return 1
  331.         fi
  332.     done
  333.  
  334.     if [ -n "$CHECK" ] && ! "$CHECK" "/dev/mapper/${dst}_unformatted" $CHECKARGS; then
  335.         log_warning_msg "$dst: the check for '/dev/mapper/$dst' failed"
  336.         cryptsetup luksClose "${dst}_unformatted"
  337.         return 1
  338.     fi
  339.  
  340.     return 0
  341. }
  342.  
  343. # Setup a regular mapping
  344. do_noluks () {
  345.     local pre_out tried keyscriptarg
  346.     tried=0
  347.     keyscriptarg=""
  348.  
  349.     if [ -z "$PRECHECK" ]; then
  350.         PRECHECK="/lib/cryptsetup/checks/un_blkid"
  351.     fi
  352.  
  353.     if ! pre_out=$("$PRECHECK" "$src" 2> /dev/null) && \
  354.        [ "$MAKESWAP" != "yes" ] && \
  355.        ! /lib/cryptsetup/checks/blkid "$src" swap >/dev/null; then
  356.         log_warning_msg "$dst: the precheck for '$src' failed: $pre_out"
  357.         return 1
  358.     fi
  359.  
  360.     if [ -n "$KEYSCRIPT" ]; then
  361.         # keyscript => "key" is just an argument to the keyscript
  362.         keyscriptarg="$key"
  363.         key="-"
  364.     elif [ -z "$key" ]; then
  365.         # no keyscript, no key => password
  366.         keyscriptarg="Unlocking the disk $src ($dst)\nEnter passphrase: "
  367.         key="-"
  368.         if [ -x /bin/plymouth ] && plymouth --ping; then
  369.             KEYSCRIPT="plymouth ask-for-password --prompt"
  370.             keyscriptarg=$(printf "$keyscriptarg")
  371.         else
  372.             KEYSCRIPT="/lib/cryptsetup/askpass"
  373.         fi
  374.     else
  375.         # no keyscript, key => file input
  376.         keyscriptarg=""
  377.         key="$key"
  378.         KEYSCRIPT=""
  379.     fi
  380.  
  381.     PARAMS="$PARAMS --key-file=$key"
  382.  
  383.     while [ "$tried" -lt "$TRIES" ]; do
  384.         if [ -n "$KEYSCRIPT" ]; then
  385.             $KEYSCRIPT "$keyscriptarg" | cryptsetup $PARAMS create "${dst}_unformatted" "$src"
  386.         else
  387.             cryptsetup $PARAMS create "${dst}_unformatted" "$src"
  388.         fi
  389.  
  390.         if [ -z "$CHECK" ] || "$CHECK" "/dev/mapper/${dst}_unformatted" $CHECKARGS; then
  391.             break
  392.         else
  393.             log_warning_msg "$dst: the check for '/dev/mapper/$dst' failed - maybe the password is wrong"
  394.             cryptsetup remove "${dst}_unformatted"
  395.         fi
  396.  
  397.         tried=$(( $tried + 1 ))
  398.         if [ "$tried" -ge "$TRIES" ]; then
  399.             return 1
  400.         fi
  401.     done
  402.  
  403.     return 0
  404. }
  405.  
  406. # Premounts file systems
  407. mount_fs () {
  408.     local point
  409.     MOUNTED=""
  410.  
  411.     for point in $MOUNT; do
  412.         if mount "$point" >/dev/null; then
  413.             MOUNTED="$MOUNTED $point"
  414.         fi
  415.     done
  416. }
  417.  
  418. # Postunmounts file systems
  419. umount_fs () {
  420.     local point
  421.  
  422.     for point in $MOUNTED; do
  423.         umount "$point" >/dev/null
  424.     done
  425. }
  426.  
  427. # Prepares swap partitions using random keys
  428. do_swap () {
  429.     local swap_out
  430.  
  431.     if [ "$MAKESWAP" != "yes" ] || [ ! -b "/dev/mapper/${dst}_unformatted" ]; then
  432.         return 0
  433.     fi
  434.  
  435.     if swap_out=$(/lib/cryptsetup/checks/un_blkid "/dev/mapper/${dst}_unformatted" 2> /dev/null) || \
  436.        /lib/cryptsetup/checks/blkid "/dev/mapper/${dst}_unformatted" swap > /dev/null 2>&1; then
  437.         mkswap "/dev/mapper/${dst}_unformatted" > /dev/null 2>&1
  438.     else
  439.         log_warning_msg "$dst: the check for '/dev/mapper/$dst' failed. /dev/mapper/$dst contains data: $swap_out"
  440.         do_close
  441.         return 1
  442.     fi
  443.  
  444.     return 0
  445. }
  446.  
  447. # Prepares tmp partitions using random keys
  448. do_tmp () {
  449.     if [ "x$TMPFS" = "x" ] || [ ! -b "/dev/mapper/${dst}_unformatted" ]; then
  450.         return 0
  451.     fi
  452.  
  453.     mkfs -t $TMPFS -q "/dev/mapper/${dst}_unformatted" > /dev/null 2>&1 || return 1
  454.     mkdir -p "/var/run/cryptsetup/$dst"
  455.     mount -t $TMPFS "/dev/mapper/${dst}_unformatted" "/var/run/cryptsetup/$dst" || return 1
  456.     chmod 1777 "/var/run/cryptsetup/$dst"
  457.     umount "/var/run/cryptsetup/$dst"
  458.     return 0
  459. }
  460.  
  461. # Rename the device from its temp name to its final name, which will
  462. # trigger mountall
  463. finalize_device () {
  464.     dmsetup rename "${dst}_unformatted" "$dst"
  465. }
  466.  
  467. # Removes a mapping
  468. do_close () {
  469.     local found IFS opt
  470.  
  471.     found="no"
  472.     IFS=','
  473.     for opt in $opts; do
  474.         if [ "$opt" = "luks" ]; then
  475.             found="yes"
  476.             break
  477.         fi
  478.     done
  479.  
  480.     if [ "$found" = "yes" ]; then
  481.         cryptsetup luksClose "$dst"
  482.     else
  483.         cryptsetup remove "$dst"
  484.     fi
  485.     return $?
  486. }
  487.  
  488. load_optimized_module () {
  489.     local module optmodule
  490.     module="$1"
  491.  
  492.     optmodule=$(find "/lib/modules/$(uname -r)/kernel/arch" -name "${module}*.ko" 2> /dev/null)
  493.     if [ -n "$optmodule" ] && [ "$(echo -n "$optmodule" | wc -l)" -eq 1 ]; then
  494.         modprobe "$optmodule" 2>/dev/null && return 0
  495.     fi
  496.  
  497.     modprobe "$module" 2>/dev/null || return 1
  498.     return 0
  499. }
  500.  
  501. # Sets up all entries in crypttab
  502. handle_crypttab_line_start () {
  503.     dst=$1
  504.     src=$2
  505.     key=$3
  506.     opts=$4
  507.  
  508.     # Make sure that all fields are present
  509.     if [ -z "$dst" ]; then
  510.         return 1
  511.     elif [ -z "$src" ] || [ -z "$key" ] || [ -z "$opts" ]; then
  512.         device_msg "$dst" "skipped, missing parameters"
  513.         return 1
  514.     fi
  515.  
  516.     # parse UUID= symlinks
  517.     if [ "${src#UUID=}" != "$src" ]; then
  518.         src="/dev/disk/by-uuid/${src#UUID=}"
  519.     elif [ "${src#LABEL=}" != "$src" ]; then
  520.         src="/dev/disk/by-label/${src#LABEL=}"
  521.     fi
  522.  
  523.     # Do the preparatory steps
  524.     if ! parse_opts "$opts"; then
  525.         device_msg "$dst" "invalid opts"
  526.         return 1
  527.     fi
  528.  
  529.     # Ignore noauto devices
  530.     if [ "$IGNORE" = "yes" ] && [ -z "$FORCE_START" ]; then
  531.         device_msg "$dst" "ignored"
  532.         return 0
  533.     fi
  534.  
  535.     if ! check_key; then
  536.         device_msg "$dst" "invalid key"
  537.         return 1
  538.     elif ! lo_setup; then
  539.         device_msg "$dst" "loopback failed"
  540.     fi
  541.  
  542.     # Export crypttab fields as environment variables
  543.     export CRYPTTAB_NAME="$dst"
  544.     export CRYPTTAB_SOURCE="$src"
  545.     export CRYPTTAB_KEY="$key"
  546.  
  547.     # Make sure source device exists
  548.     if [ ! -r "$src" ]; then
  549.         if [ "$LOUD" = "yes" ]; then
  550.             device_msg "$dst" "skipped, device $src does not exist"
  551.             return 1
  552.         fi
  553.         return 0
  554.     fi
  555.  
  556.     # Make sure that target device doesn't exist
  557.     if [ -b "/dev/mapper/${dst}_unformatted" ] || [ -b "/dev/mapper/$dst" ]; then
  558.         device_msg "$dst" "running"
  559.         return 0
  560.     fi
  561.  
  562.     # All checks passed, do the real setup
  563.     log_action_msg "$dst (starting).."
  564.     result="ok"
  565.     if [ "$USELUKS" = "yes" ]; then
  566.         do_luks || result="fail"
  567.     else
  568.         do_noluks || result="fail"
  569.     fi
  570.  
  571.     # Finish up
  572.     if [ "$result" != "ok" ]; then
  573.         rm_lo_setup
  574.         device_msg "$dst" "failed"
  575.         return 1
  576.     else
  577.         do_swap
  578.         do_tmp
  579.         finalize_device
  580.         device_msg "$dst" "started"
  581.     fi
  582.  
  583.     return 0
  584. }
  585.  
  586. handle_crypttab_line_stop () {
  587.     dst=$1
  588.     src=$2
  589.     key=$3
  590.     opts=$4
  591.  
  592.     if [ ! -b "/dev/mapper/$dst" ]; then
  593.         device_msg "$dst" "stopped"
  594.         return 0
  595.     fi
  596.  
  597.     opencount=$(dmsetup info -c --noheadings -o open "$dst" 2> /dev/null || true)
  598.     if [ -z "$opencount" ]; then
  599.         device_msg "$dst" "error"
  600.         return 1
  601.     elif [ "$opencount" != "0" ]; then
  602.         device_msg "$dst" "busy"
  603.         if [ "$INITSTATE" = "early" ] || [ "$INITSTATE" = "manual" ]; then
  604.             return 1
  605.         fi
  606.         return 0
  607.     fi
  608.  
  609.     #major=$(dmsetup info -c --noheadings -o major "$dst" 2> /dev/null || true)
  610.     #minor=$(dmsetup info -c --noheadings -o minor "$dst" 2> /dev/null || true)
  611.     src_major=$(dmsetup deps "$dst" 2> /dev/null | sed -e 's/^.*(\([0-9]*\), [0-9]*)$/\1/g' || true)
  612.     src_minor=$(dmsetup deps "$dst" 2> /dev/null | sed -e 's/^.*([0-9]*, \([0-9]*\))$/\1/g' || true)
  613.  
  614.     if [ -z "$src_major" ] || [ -z "$src_minor" ]; then
  615.         device_msg "$dst" "error"
  616.         return 1
  617.     fi
  618.     
  619.     do_close || return $?
  620.  
  621.     # Detach loopback device, if attached
  622.     if [ "$src_major" = "7" ]; then
  623.         loopdev="/dev/loop${src_minor}"
  624.         if ! rm_lo_setup; then
  625.             device_msg "$dst" "detaching loopback failed"
  626.             return 1
  627.         fi
  628.     fi
  629.  
  630.     device_msg "$dst" "stopping"
  631.  
  632.     return 0
  633. }
  634.  
  635. do_start () {
  636.     local dst src key opts result
  637.  
  638.     modprobe -qb dm-mod || true
  639.     modprobe -qb dm-crypt || true
  640.     dmsetup mknodes > /dev/null 2>&1 || true
  641.     log_action_begin_msg "Starting $INITSTATE crypto disks"
  642.     mount_fs
  643.  
  644.     egrep -v "^[[:space:]]*(#|$)" "$TABFILE" | while read dst src key opts; do
  645.         handle_crypttab_line_start "$dst" "$src" "$key" "$opts" <&3 || log_action_end_msg $?
  646.     done 3<&1
  647.     umount_fs
  648.  
  649.     log_action_end_msg 0
  650. }
  651.  
  652. # Removes all mappings in crypttab
  653. do_stop () {
  654.     local dst src key opts opencount major minor loopmajor
  655.  
  656.     dmsetup mknodes
  657.     log_action_begin_msg "Stopping $INITSTATE crypto disks"
  658.     loopmajor=$(grep "[[:space:]]*loop$" /proc/devices | sed 's/^[[:space:]]*//;s/[[:space:]].*//')
  659.  
  660.     egrep -v "^[[:space:]]*(#|$)" "$TABFILE" | while read dst src key opts; do
  661.         handle_crypttab_line_stop "$dst" "$src" "$key" "$opts" <&3 || log_action_end_msg $?
  662.     done 3<&1
  663.  
  664.     log_action_end_msg 0
  665. }
  666.  
  667. # Convenience function to handle $VERBOSE
  668. device_msg () {
  669.     local dst msg
  670.     dst="$1"
  671.     msg="$2"
  672.  
  673.     if [ "$VERBOSE" != "no" ]; then
  674.         log_action_cont_msg "$dst ($msg)"
  675.     fi
  676. }
  677.